<?php
/*
 * @Author: 李志刚
 * @CopyRight: 2020-2030 衡水山木枝技术服务有限公司
 * @Date: 2021-10-19 10:21:47
 * @Description: 订单基础表，下单时需要拆分到每个门店，积分/平台券所占用的金额要按门店订单金额比例拆分到每家
 * @LastEditors: 李志刚
 * @LastEditTime: 2021-10-19 17:44:22
 * @FilePath: /归档/base/2021_10_19_102147_create_order.php
 */

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrder extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->engine = 'InnoDB';
            $table->id();
            $table->foreignId('user_id')->default(0)->comment('用户ID');
            $table->foreignId('shop_id')->default(0)->comment('门店ID');
            $table->foreignId('tuan_id')->default(0)->comment('团购ID');
            // $table->integer('t_orderid')->default(0)->comment('团购用户ID');
            $table->char('order_sn', 15)->comment('订单编号')->unique('order_sn');
            $table->integer('pay_order_id')->default(0)->comment('支付订单ID');
            $table->unsignedDecimal('total_price')->default(0)->comment('支付总金额');
            $table->unsignedDecimal('coupon_price')->default(0)->comment('总优惠金额');
            $table->unsignedDecimal('delivery_fee')->default(0)->comment('运费');
            $table->unsignedDecimal('pay_price')->default(0)->comment('最终支付金额');
            // 优惠券可能需要拆分成关联，平台券与店铺券同时可以用
            $table->integer('user_coupon_id')->default(0)->comment('用户优惠券ID');
            $table->tinyInteger('fare_type')->default(0)->comment('0邮寄1自提');
            $table->integer('address_id')->default(0)->comment('收件地址id');
            $table->char('phone', 11)->nullable()->comment('收件人电话');
            $table->string('address', 255)->nullable()->comment('收件人地址');
            $table->string('person', 20)->nullable()->comment('收件人姓名');
            $table->tinyInteger('pay_type')->default(1)->comment('支付方式 1微信 2余额 3混合');
            $table->tinyInteger('pay_status')->default(0)->comment('0未支付1支付中2支付完成');
            $table->dateTime('pay_at')->nullable()->comment('支付时间');
            $table->tinyInteger('ship_status')->default(0)->comment('发货状态 0未发货 1已发货');
            $table->dateTime('ship_at')->nullable()->comment('发货时间');
            $table->dateTime('confirm_at')->nullable()->comment('确认收货时间');
            $table->string('user_mark', 255)->nullable()->comment('用户备注');
            $table->string('shop_mark', 255)->nullable()->comment('商家备注');
            $table->tinyInteger('order_status')->default(1)->comment('1正常2完成0关闭');
            $table->tinyInteger('is_account')->default(0)->comment('是否已经分账（0 未分账 1已分账）');
            $table->integer('account_log_id')->default(0)->comment('分账记录ID');
            $table->tinyInteger('prom_type')->default(0)->comment('类型：0正常，1抢，2团');
            $table->tinyInteger('del_flag')->default(0)->comment('删除状态（1删除 0正常）');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
